
//获得鼠标坐标值
function mousePosition(ev) {
	if (ev.pageX || ev.pageY) {
		return {
			x : ev.pageX,
			y : ev.pageY
		};
	}
	return {
		x : ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y : ev.clientY + document.body.scrollTop - document.body.clientTop
	};
}

//获得事件对象
function getEvent() // 同时兼容ie和ff的写法
{
	if (document.all)
		return window.event;
	func = getEvent.caller;
	while (func != null) {
		var arg0 = func.arguments[0];
		if (arg0) {
			if ((arg0.constructor == Event || arg0.constructor == MouseEvent)
					|| (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
				return arg0;
			}
		}
		func = func.caller;
	}
	return null;
}

//改变层的坐标值实例
function mouseMove(city) {
	var ev = getEvent();
	var mousePos = mousePosition(ev);
	var show = document.getElementById('Layer1');
	var mycity = document.getElementById('mycity');
	mycity.innerHTML = city;
	show.style.display = 'block';
	show.style.left = mousePos.x + 10;
	show.style.top = mousePos.y + 10;
}

// /////////////////树级联多选////////////////////////
// 判断是否有子结点被选中
var childHasChecked = function(node) {
	var childNodes = node.childNodes;
	if (childNodes || childNodes.length > 0) {
		for (var i = 0; i < childNodes.length; i++) {
			if (childNodes[i].getUI().checkbox.checked)
				return true;
		}
	}
	return false;
}

// 级联选中父节点
var parentCheck = function(node, checked) {
	var checkbox = node.getUI().checkbox;
	if (typeof checkbox == 'undefined')
		return false;
	if (!(checked ^ checkbox.checked))
		return false;
	if (!checked && childHasChecked(node))
		return false;
	checkbox.checked = checked;
	node.attributes.checked = checked;
	node.getUI().checkbox.indeterminate = checked; // 半选中状态
	node.getOwnerTree().fireEvent('check', node, checked);
	var parentNode = node.parentNode;
	if (parentNode !== null) {
		parentCheck(parentNode, checked);
	}
}

// 增加checkchange监听
var checkchangeall = function(node, checked) {
	var parentNode = node.parentNode;
	if (parentNode !== null) {
		parentCheck(parentNode, checked);
	}
	node.expand();
	node.attributes.checked = checked;
	node.eachChild(function(child) {
				child.ui.toggleCheck(checked);
				child.attributes.checked = checked;
				child.fireEvent('checkchange', child, checked);
			});
}
// ///////////////////级联多选树///////////////////////////////////

// //////////////////级联单选树///////////////////////////////////
// 获取所有的node
var getNodes = function(node) {
	var startNode = node.getOwnerTree().getRootNode();
	var r = [];
	var f = function() {
		r.push(this);
	};
	startNode.cascade(f);
	return r;
};
// 真对单选进行处理
var nodeAllRadioChange = function(node) {
	var nodes = getNodes(node);
	if (nodes && nodes.length > 0) {
		for (var i = 0, len = nodes.length; i < len; i++) {
			if (nodes[i].id != node.id) {
				if (nodes[i].getUI().checkbox) {
					nodes[i].getUI().checkbox.checked = false;
				}
			}
		}
	}
};
// weightTreePanel.on("checkchange",nodeAllRadioChange);
// var b = tree.getChecked(); b[0].id
// //////////////////级联单选树///////////////////////////////////

function panelMask(panel, mesage) {
	// var portlet = item.ownerCt.ownerCt.ownerCt.ownerCt;
	panel.getEl().mask(mesage + '...');
	// setTimeout("com.mainPanel.getEl().unmask();",3000);
}

function panelUNMask(panel) {
	panel.getEl().unmask();
}

/*******************************************************************************
 * 带参数传递的sttimeout JTimeout(show_date_time, 1000, new Date(eval("new " +
 * eval(currTime).source)), new Date(eval("new " + eval(sysTime).source)));
 * 第一个参数为你要运行的函数， 第二个参数为延迟，后面可以跟任意多个参数
 * 
 * @param {}
 *            funcName
 * @param {}
 *            time
 * @return {}
 */
function JTimeout(funcName, time) {
	var args = [];
	for (var i = 2; i < arguments.length; i++) {
		args.push(arguments[i]);
	}
	return window.setTimeout(function() {
				funcName.apply(this, args);
			}, time);
}

function JsonToStr(obj) {
	var arr = [];
	var fmt = function(s) {
		if (typeof s == 'object' && s != null)
			return JsonToStr(s);
		return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
	}
	for (var i in obj)
		arr.push("'" + i + "':" + fmt(obj[i]));
	return '{' + arr.join(',') + '}';
}

function getFlexObject(file, flashvars, id, flexid) {
	var swfVersionStr = "10.0.0";
	var xiSwfUrlStr = "/swf/playerProductInstall.swf";
	var params = {};
	params.quality = "high";
	params.bgcolor = "#ebf4ff";
	params.allowscriptaccess = "sameDomain";
	params.allowfullscreen = "true";
	params.wmode = "Opaque";
	var attributes = {};
	attributes.id = flexid;
	attributes.name = flexid;
	attributes.align = "middle";
	swfobject.embedSWF(file, id, "100%", "100%", swfVersionStr, xiSwfUrlStr,
			flashvars, params, attributes);
	swfobject.createCSS("#" + id, "display:block;text-align:left;");
	return swfobject;
}

function getFlexObject2(file, flashvars, id, flexid, _width, _height) {
	var swfVersionStr = "10.0.0";
	var xiSwfUrlStr = "/swf/playerProductInstall.swf";
	var params = {};
	params.quality = "high";
	params.bgcolor = "#ebf4ff";
	params.allowscriptaccess = "sameDomain";
	params.allowfullscreen = "true";
	params.wmode = "Opaque";
	var attributes = {};
	attributes.id = flexid;
	attributes.name = flexid;
	attributes.align = "middle";
	swfobject.embedSWF(file, id, _width, _height, swfVersionStr, xiSwfUrlStr,
			flashvars, params, attributes);
	swfobject.createCSS("#" + id, "display:block;text-align:center;");
	return swfobject;
}

function getHtmlObject(swfLocation, params, _width, _height) {
	var html = '<object id=\"gis\" allowScriptAccess=\"always\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" '
			+ 'codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" '
			+ 'width=\"'
			+ _width
			+ '\" height=\"'
			+ _height
			+ '\"><param name=\"movie\" value=\"'
			+ swfLocation
			+ '\" />'
			+ '<param name=\"wmode\" value=\"Opaque\" /><param name=\"quality\" value=\"high\" />'
			+ '<param name=\"FlashVars\" value=\"'
			+ params
			+ '\" />'
			+ '<embed src=\"'
			+ swfLocation
			+ '\" allowScriptAccess=\”always\” wmode=\"Opaque\" quality=\"high\" '
			+ 'FlashVars=\"'
			+ params
			+ '\"'
			+ 'pluginspage=\"http://www.macromedia.com/go/getflashplayer\" '
			+ 'type=\"application/x-shockwave-flash\" width=\"'
			+ _width
			+ '\" height=\"' + _height + '\">' + '</embed></object>';
	return html;
}

Array.prototype.removeItem = function(dx) {
	if (isNaN(dx) || dx > this.length) {
		return false;
	}
	for (var i = 0, n = 0; i < this.length; i++) {
		if (this[i] != this[dx]) {
			this[n++] = this[i]
		}
	}
	this.length -= 1
};

Date.prototype.format = function(format) {
	var o = {
		"M+" : this.getMonth() + 1, // month
		"d+" : this.getDate(), // day
		"h+" : this.getHours(), // hour
		"m+" : this.getMinutes(), // minute
		"s+" : this.getSeconds(), // second
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		"S" : this.getMilliseconds()
	};
	if (/(y+)/.test(format))
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
						- RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(format))
			format = format.replace(RegExp.$1, RegExp.$1.length == 1
							? o[k]
							: ("00" + o[k]).substr(("" + o[k]).length));
	return format;
}

function getPanelMainId(mainFrame, name) {
	var tabPanel = Ext.getCmp(mainFrame);
	var item = tabPanel.getComponent(0);
	var _name = item.name;
	if (_name == name) {
		return 1;
	} else {
		return 0;
	}
}

// 点击菜单创建主panel
function createPanel(panelName, mainFrame) {
	if (Ext.isIE) {
		CollectGarbage();
	}
	var tabPanel = Ext.getCmp(mainFrame);
	var exist = false;
	for (var i = 0; i < tabPanel.items.length; i++) {
		var item = tabPanel.getComponent(i);
		if (item.id != panelName) {
			tabPanel.remove(item);
			item.destroy();
			item = null;
			delete item;
		} else {
			exist = true;
			tabPanel.activate(item.id);
		}
	}
	if (!exist) {
		var createPanelString = 'new ' + panelName;
		var panel = eval(createPanelString);
		panel.id = panelName;
		// panel.closable = true;
		tabPanel.add(panel);
		tabPanel.activate(panelName);
	}
};

// 更新创建tabPanel组件
function createPanel2(panelName, mainFrame) {
	if (Ext.isIE) {
		CollectGarbage();
	}
	var tabPanel = Ext.getCmp(mainFrame);
	for (var i = 0; i < tabPanel.items.length; i++) {
		var item = tabPanel.getComponent(i);
		tabPanel.remove(item);
		item.destroy();
		item = null;
		delete item;
	}
	var createPanelString = 'new ' + panelName;
	var panel = eval(createPanelString);
	panel.id = panelName;
	tabPanel.add(panel);
	tabPanel.activate(panelName);
	treePanel.doLayout();
};

// 更新创建panel组件
function createPanelItem(panelName, mainFrame) {
	if (Ext.isIE) {
		CollectGarbage();
	}
	var tabPanel = Ext.getCmp(mainFrame);
	for (var i = 0; i < tabPanel.items.length; i++) {
		var item = tabPanel.getComponent(i);
		tabPanel.remove(item);
		item.destroy();
		item = null;
		delete item;
	}
	var createPanelString = 'new ' + panelName;
	var panel = eval(createPanelString);
	panel.id = panelName;
	tabPanel.add(panel);
	tabPanel.doLayout();
};

function createPanelItemClass(panelName, panel, mainFrame) {
	if (Ext.isIE) {
		CollectGarbage();
	}
	var tabPanel = Ext.getCmp(mainFrame);
	for (var i = 0; i < tabPanel.items.length; i++) {
		var item = tabPanel.getComponent(i);
		tabPanel.remove(item);
		item.destroy();
		item = null;
		delete item;
	}
	try {
		panel.id = panelName;
	} catch (e) {
	}
	tabPanel.add(panel);
	tabPanel.doLayout();
};

function createPanelIndexClass(index, panel, mainFrame) {
	if (Ext.isIE) {
		CollectGarbage();
	}
	var tabPanel = Ext.getCmp(mainFrame);
	var item = tabPanel.getComponent(index);
	tabPanel.remove(item);
	item.destroy();
	item = null;
	delete item;
	tabPanel.insert(index, panel);
	tabPanel.doLayout();
};

function createPanelItemOneClass(panel, mainFrame) {
	if (Ext.isIE) {
		CollectGarbage();
	}
	var tabPanel = Ext.getCmp(mainFrame);
	var item = tabPanel.getComponent(tabPanel.items.length - 1);
	tabPanel.remove(item);
	item.destroy();
	item = null;
	delete item;
	panel.id = 'new_panel_id' + Math.random();
	tabPanel.add(panel);
	tabPanel.doLayout();
};

// 克隆对象数据方法
function clone(myObj) {
	if (typeof(myObj) != 'object')
		return myObj;
	if (myObj == null)
		return myObj;
	var myNewObj = new Object();
	for (var i in myObj)
		myNewObj[i] = clone(myObj[i]);
	return myNewObj;
}

function cloneArray(array) {
	var arr = new Array();
	for (i = 0; i < array.length; i++) {
		arr[i] = clone(array[i]);
	}
	return arr;
}

function trimForRN2(str) {
	if (str == null || str == '' || typeof(str) != 'string') {
		return '';
	}
	var Start = 0; // 截取字符串的开始位子
	var End = 0; // 截取字符串的结束位子
	var bol = true;
	for (i = 0; i < str.length; i++) {
		if (bol == true)
			Start = i;
		if (str.charCodeAt(i) != 32 && str.charCodeAt(i) != 10
				&& str.charCodeAt(i) != 13) {
			End = i + 1;
			bol = false;
		}
	}
	if (End == 0 && str.length > 0) {
		return '';
	}
	return str.substring(Start, End);
}

// 动态载入js及css文件
function loadjscssfile(filename, filetype) {
	var fileref;
	if (filetype == "js") { // 判断文件类型
		fileref = document.createElement('script');// 创建标签
		fileref.setAttribute("type", "text/javascript");
		// 定义属性type的值为text/javascript
		fileref.setAttribute("src", filename);// 文件的地址
	} else if (filetype == "css") { // 判断文件类型
		fileref = document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", filename);
	}
	if (typeof fileref != "undefined")
		document.getElementsByTagName("head")[0].appendChild(fileref);
	return 1;
}

function loadMenuPanel(filename, filetype, link) {
	if (filetype == "js") { // 判断文件类型
		for (i = 0; i < filename.length; i++) {
			var file = filename[i];
			var fileref = document.createElement('script');// 创建标签
			fileref.setAttribute("type", "text/javascript");// 定义属性type的值为text/javascript
			fileref.setAttribute("src", file);// 文件的地址
			document.getElementsByTagName("head")[0].appendChild(fileref);
		}
	} else if (filetype == "css") { // 判断文件类型
		for (i = 0; i < filename.length; i++) {
			var file = filename[i];
			var fileref = document.createElement("link");
			fileref.setAttribute("rel", "stylesheet");
			fileref.setAttribute("type", "text/css");
			fileref.setAttribute("href", file);
			document.getElementsByTagName("head")[0].appendChild(fileref);
		}
	}
	return 1;
}

function getPreDate() {
	var lastday = new Date();
	lastday.setTime(lastday.getTime() - 24 * 3600 * 1000);
	return lastday;
}

function getNextDate() {
	var lastday = new Date();
	lastday.setTime(lastday.getTime() + 24 * 3600 * 1000);
	// menu.getNextDate(function(data){if(data!=null && data!="") lastday = new
	// Date(data);});
	return lastday;
}

function getSysDate() {
	var today = new Date();
	var day = today.getDate();
	var month = today.getMonth() + 1;
	var year = today.getFullYear();
	var hours = today.getHours();
	var minute = today.getMinutes();
	month = month < 10 ? "0" + month : month;// 如果小于10即显示为09月
	day = day < 10 ? "0" + day : day;// 如果小于10即显示为09日
	var zt_Month = today.getMonth() * 1 + 1;
	var zt_date = today.getDate();
	zt_Month = zt_Month < 10 ? "0" + zt_Month : zt_Month;
	zt_date = zt_date < 10 ? "0" + zt_date : zt_date;
	var date = year + "-" + month + "-" + day;
	return date;
}

function GetColor() {
	var len = random_color.length; // 获取颜色值的数目
	var num = Math.random(); // random()产生一个0~1之间的随机数。round（x）对x四舍五入取整数.
	var t = Math.round(num * (len - 1)) + 1; // 获取一个随机数
	return random_color[t];
}

function GetColor2() {
	var r = Math.floor(Math.random() * 255).toString(16);
	var g = Math.floor(Math.random() * 255).toString(16);
	var b = Math.floor(Math.random() * 255).toString(16);
	r = r.length == 1 ? "0" + r : r;
	g = g.length == 1 ? "0" + g : g;
	b = b.length == 1 ? "0" + b : b;
	return "#" + r + g + b;
}

var getRandomColor = function() {
	return '#'
			+ ('00000' + (Math.random() * 0x1000000 << 0).toString(16))
					.substr(-6);
}

function isEmpty(value) {
	value = value.replace(/[ ]/g, '');
	if (value.length < 1) {
		return true;
	}
	return false;
}

// 通过移动小数点 扩大倍数 将科学计数法转换成整数
function scienceNum(value) {
	if (!isEmpty(value)) {
		var num = 0;
		if ((num = value.indexOf('E')) != -1
				|| (num = value.indexOf('e')) != -1) {
			var doubleStr = value.substring(0, num);
			var eStr = value.substring(num + 1, value.length);
			eStr = parseInt(eStr);
			var doubleStrList = doubleStr.split('.');
			var doubleStr1 = doubleStrList[0];
			var doubleStr2 = doubleStrList[1];

			if (doubleStr2.length > eStr) {
				var nums = doubleStr2.substring(0, eStr);
				var nume = doubleStr2.substring(eStr, doubleStr2.length);
				doubleStr = doubleStr1 + nums + '.' + nume;
			} else if (doubleStr2.length < eStr) {
				var indexNum = eStr - doubleStr2.length;
				// 用0补齐
				var str = '';
				for (var i = 0; i < indexNum; i++) {
					str += '0';
				}
				doubleStr = doubleStr1 + doubleStr2 + str;
			} else {
				doubleStr = doubleStr1 + doubleStr2;
			}
			value = doubleStr;
			// 千分位
		}
	}
	return value;
}

function getcurTime() {
	var hours, minutes, seconds, ap;
	var intHours, intMinutes, intSeconds;
	var today, javatime;
	today = new Date();
	intHours = today.getHours();
	intMinutes = today.getMinutes();
	intSeconds = today.getSeconds();
	if ((intMinutes + "").length < 2) {
		intMinutes = "0" + intMinutes;
	}

	if (intHours == 0) {
		hours = "12:";
		ap = " AM";
	} else if (intHours < 12) {
		hours = intHours + ":";
		ap = " AM";
	} else if (intHours == 12) {
		hours = "12:";
		ap = " PM";
	} else {
		intHours = intHours - 12
		hours = intHours + ":";
		ap = " PM";
	}
	minutes = intMinutes;
	timeString = hours + minutes + ap;
	return timeString;
}

/** * 检查是否为数 ** */
isNumber = function(s) {
	s.trim();
	return (s.search(/^[+-]?[0-9.]*$/) >= 0);
}

isIP = function(v) {
	return /^(\+?[1-9][0-9]?|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
			.test(v);
}

function getRandNumber() {
	return 10 + parseInt(Math.random() * 90);
}

function checkIE() {
	if ((navigator.userAgent.indexOf('MSIE') >= 0)
			&& (navigator.userAgent.indexOf('Opera') < 0)) {
		return "ie";
	} else if (navigator.userAgent.indexOf('Firefox') >= 0) {
		return "firefox";
	} else if (navigator.userAgent.indexOf('Opera') >= 0) {
		return "opera";
	} else {
		return "other";
	}
}
